#pragma once 

#include <stdio.h>
#include <time.h>
#include <iostream>
#include <string>
using namespace std;



//定义一个时间戳 time_t time(time_t *t);
// struct tm *localtime(const time_t *timep);
class TimeStamp
{
    public:
        //获取时间戳
        static void GetTimeStamp(string* timestamp)
        {
            //总秒数
            time_t sys_time;
            time(&sys_time);
            //正常的yyyy-mm-dd hh:mm:ss 
            struct tm* t = localtime(&sys_time);
            char buf[30] = {'\0'};
            //按照格式写入到buf中去
            snprintf(buf,sizeof(buf)-1,"%04d-%02d-%02d %02d:%02d:%02d",t->tm_year + 1900,t->tm_mon + 1,t->tm_mday,t->tm_hour,t->tm_min,t->tm_sec);
            timestamp->assign(buf,sizeof(buf));
        }
};
//日志等级
enum LogLevel
{
    INFO = 0,
    WARNING,
    ERROR,
    FATAL,
    DEBUG
};

//等级中文显示
const char* LevelInfo[] = 
{
    "INFO",
    "WARNING",
    "ERROR",
    "FATAL",
    "DEBUG"
};


//输出格式[时间戳 等级 文件名 行数] 信息
std::ostream& Log(LogLevel loglevel,const char* file,int line,const string msg)
{
    string timestamp;
    TimeStamp::GetTimeStamp(&timestamp);
    string level = LevelInfo[loglevel];
    cout << "[" << timestamp << ' ' << level << " " << file << " " << line << "]" << " " <<  msg;
    return std::cout;
}

#define LOG(loglevel,msg) Log(loglevel,__FILE__,__LINE__,msg)






